package com.lc202407;

public class Solution3115 {
    public static int maximumPrimeDifference(int[] nums) {
        int length = nums.length;
        int start = 0;
        int end = 0;
        for (int i = 0; i < length; i++) {
            if (hasPrimeNum(nums[i])) {
                start = i;
                break;
            }
        }
        for (int i = length - 1; i >= 0; i--) {
            if (hasPrimeNum(nums[i])) {
                end = i;
                break;
            }
        }
        return end - start;
    }

    public static boolean hasPrimeNum(int num) {
        if (num == 1) {
            return false;
        }
        if (num == 2 || num == 3) {
            return true;
        }
        for (int i = 2; i < num; i++) {
            if (num % i == 0) {
                return false;
            }
            if (i >= (num / (double) i)) {
                break;
            }
        }

        return true;
    }

    public static void main(String[] args) {
        maximumPrimeDifference(new int[]{1, 7});
    }
}
